\documentclass[12pt]{article}
\textwidth 165mm
\textheight 210mm
\oddsidemargin  1mm
\evensidemargin  1mm
\topmargin 1mm
\usepackage[latin1]{inputenc}

\begin{document}

\begin{center}
{\Large \bf Example 1 using OC-TQ:

Calculations in the binary Cr-Fe  system

with a miscibility gap in the bcc phase

}

\bigskip

Bo Sundman \today

\end{center}

This is an example for the Fortran OCTQ interface.

The example is based on the TQ standard for interfacing thermodynamic
software with application software.  A more extensive interface called
OpenCalphad Application Software Interface (OCASI) is under
development.

If you are not familiar with compiling and linking software and do not
understand the intructions here please ask some guru close to you for
help.  The instructions here are very brief but I do not have time to
answer questions about how to compile and link software.  If you find
errors you are welcome to report them.

To link this example you must first install the OC main program.  This
installation generates two files you need: {\bf liboceq.a} and {\bf
  liboceqplus.mod}.  Both of these files are needed for these
applications.

You also need the {\bf liboctq.F90} source code which is on the
directory above.

\bigskip

{\bf Files on this directory:}
\begin{itemize}
\item crfe.TDB is a small database in the TDB format.
\item link-tqtest1 is a text file without extention which you can use
  as command file a on Windows system if you add the extention .cmd
  and execute it a batch file in a terminal window (or if you double
  click on it).  If you use LINUX you have to edit it to create a
  Makefile or give the corresponing commands interactively.

  In the link-tqtest1 file there are some additional comments and
  instructions.  If you do not understand these instruction please ask
  a local guru for help.
\item readme-tq1.pdf is this file.
\item readme-tql.tex is a LaTeX file to generate this pdf file.
\item TQ1-crfe.F90 is the test1 program written in Fortran95/08.
\end{itemize}

\newpage

{\bf Compiling and linking the test program}

\bigskip

When you have executed the link-tqtest1 file in a terminal window (or
the corresponding Makefile) you should have a program called
tqtest1.exe.  The linking below assumes that the OC main program and
the corresponing libraries will be two directories above this one.

The output during compiling and linking will be something like:

{\small
\begin{verbatim}

C:\Users...\TQ4lib\F90\crfe>link-tqtest1
C:\Users...\TQ4lib\F90\crfe>REM command file to cretate test program 1 for OCASI/TQ
C:\Users...\TQ4lib\F90\crfe>REM Either execute the commands below interactivly or rename
C:\Users...\TQ4lib\F90\crfe>REM this file with extention .cmd and execute it
C:\Users...\TQ4lib\F90\crfe>REM YOU MUST HAVE COMPILED AND LINKED THE MAIN OC PROGRAM
C:\Users...\TQ4lib\F90\crfe>REM The copy commands assume you are on the directory
C:\Users\...\TQ4lib\F90\crfe>REM TQ4lib/F90/test1
C:\Users\...\TQ4lib\F90\crfe>REM and have the main program three directories up
C:\Users\...\TQ4lib\F90\crfe>REM as when you downloaded the zip file with the program
C:\Users\...\TQ4lib\F90\crfe>copy ..\..\..\liboceq.a .
        1 file(s) copied.
C:\Users\...\TQ4lib\F90\crfe>copy ..\..\..\liboceqplus.mod .
        1 file(s) copied.
C:\Users\...\TQ4lib\F90\crfe>REM copy ..\ftinyopen-dummy.F90 .
C:\Users\...\TQ4lib\F90\crfe>copy ..\liboctq.F90 .
        1 file(s) copied.
C:\Users\...\TQ4lib\F90\crfe>REM gfortran -c ftinyopen-dummy.F90
C:\Users\...\TQ4lib\F90\crfe>gfortran -c liboctq.F90
C:\Users\...\TQ4lib\F90\crfe>gfortran -o tqex1 TQ1-crfe.F90 liboctq.o liboceq.a
C:\Users\...\TQ4lib\F90\crfe>

\end{verbatim}
}

\newpage

\bigskip

{\bf Running the test program}

\bigskip

When you execute this program in a terminal window you have to answer
some questions.  If you just press RETURN at the questions the default
value (given within slashes //) will be take.  This example calls a
routine TQLR in the TQ interface which generates a listing of the
claculated equilibrium and is mainly intended for debugging.

Depending on your input you should obtain an output similar to the
text below.  Comment are inserted in {\em italics}.

{\small
\begin{verbatim}
C:\Users\..\TQ4lib\F90\crfe>tqex1
 tqini created: DEFAULT_EQUILIBRIUM
 Reading all elements from the database file: crfe

System with  2 elements: CR, FE,
and   4 phases: LIQUID, BCC_A2, FCC_A1, SIGMA,

\end{verbatim}
}

{\em The output above is generated by the tq\_init subroutine and the
  test program.  Below you can accept the default values of T, P and
  the mole fractions of Cr by just pressing return.  The output after
  giving the mole fraction is generated by the OC minimizer just for
  information.}

{\small
\begin{verbatim}
Give conditions:
Temperature (K): /800/:
Pressure (Pa): /100000/:
Mole fraction of CR: /0.25/:
 3Y total gridpoints:          128
 3Y Constitution of metastable phases set
Gridmin:     128 points   0.00E+00 s and       0 clockcycles, T=  800.00
Equilibrium result::   9 its,   0.0000E+00 s,      0 cc, G= -2.9963780E+04 J/mol

Successful calculation
Tuple index  Phase name                 Amount
  1          LIQUID                     0.0000
  2          BCC_A2                     0.8302
  3          FCC_A1                     0.0000
  4          SIGMA                      0.1698

Stable phase: BCC_A2, amount:   8.3018E-01, mole fractions:
CR      :  0.197577,  FE      :  0.802423,

Stable phase: SIGMA, amount:   1.6982E-01, mole fractions:
CR      :  0.506278,  FE      :  0.493722,

Component, mole fraction,  chemical potential (SER)   BCC
CR            0.250000             -2.716211E+04   -1.024353E+03
FE            0.750000             -3.089767E+04   -9.918059E+02

\end{verbatim}
}

{\em The test program first writes a list of all phases and their
  amount, then again for each stable phase the amount and
  molefractions in each phase.  Finally the the components are listed
  with their amount and their chemical potential referred to SER (the
  stable state at 298.15~K and 1 bar) and referred to BCC at the
  current T and 1 bar.

  The following output is provided by the subroutine TQLR which writes
  the same things (and a little more) using the standard way in OC.
  This can be used as a easy way to check your own output.}

{\small
\begin{verbatim}
********************
Start debug output from TQLR:
  1:T=800, 2:P=100000, 3:N=1, 4:X(CR)=0.25
 Degrees of freedom are   0
T=    800.00 K (   526.85 C), P=  1.0000E+05 Pa, V=  6.6465E-06 m3
N=   1.0000E+00 moles, B=   5.4884E+01 g, RT=   6.6516E+03 J/mol
G= -2.9964E+04 J, G/N= -2.9964E+04 J/mol, H=  1.9289E+04 J, S=  6.1566E+01 J/K
Component name    Moles      Mole-fr  Chem.pot/RT  Activities  Ref.state
CR                2.5000E-01  0.25000 -1.5400E-01  8.5727E-01  BCC_A2
FE                7.5000E-01  0.75000 -1.4911E-01  8.6148E-01  BCC_A2

Name                Status Moles      Volume    Form.Units Cmp/FU dGm/RT  Comp:
BCC_A2.................. E  8.302E-01  6.02E-06  8.30E-01    1.00  0.00E+00  X:
 FE     8.02423E-01  CR     1.97577E-01

SIGMA................... E  1.698E-01  6.23E-07  5.66E-03   30.00  0.00E+00  X:
 CR     5.06278E-01  FE     4.93722E-01

End debug output from TQLR
********************


\end{verbatim}
}

{\em The program is then finished but you can calculate again using
another T, P and composition.  In the case below the calculation is made
at 600~K when the system has a miscibility gap in the BCC phase.

We also turn on the SILENT mode which means less output from OC.}

{\small
\begin{verbatim}
Any more calculations? /N/: y
 Turning on silent mode, less output from OC

Give conditions:
Temperature (K): /800/: 600
Pressure (Pa): /100000/:
Mole fraction of CR: /0.25/:

Successful calculation
Tuple index  Phase name                 Amount
  1          LIQUID                     0.0000
  2          BCC_A2                     0.2157
  3          FCC_A1                     0.0000
  4          SIGMA                      0.0000
  5          BCC_A2_AUTO#2              0.7843

\end{verbatim}
}

{\em IMPORTANT: Note that there are now 5 phases because a second BCC
  composition set has been created.  The new phase tuple is placed
  after the inital set of phases.  The new BCC phase has the suffix
  AUTO as it is created automatically by the grid minimizer.  It also
  has the composition set number 2 after the hash character, \#2.

  The first 5 phases all have a composition set number 1.  Using OC
  interactivly you normally give the composition set number after a
  hash character but for the first composition set it is not needed.

  The two composition sets for BCC have exactly the same thermodynamic
  parameters but the BCC phase can at this temperature be stable with
  two different compositions.

  You must be aware of that new composition sets can be created
  automatically when you use the grid minimizer.  Thus the number of
  phase tuples may change.  Although a phase tuple that has been stable
  at one calculation will never be removed automatically, only explicitly.

  You can create composition sets manually and add your own pre- and
  suffix and also a default constitution.

  Note also the you had no output from the calculation as the silent
  mode was turned on.}

{\small
\begin{verbatim}

Stable phase: BCC_A2, amount:   2.1567E-01, mole fractions:
CR      :  0.970535,  FE      :  0.029465,

Stable phase: BCC_A2_AUTO#2, amount:   7.8433E-01, mole fractions:
CR      :  0.970535,  FE      :  0.029465,

Component, mole fraction,  chemical potential (SER)   BCC
CR            0.250000             -1.718694E+04   -1.364302E+02
FE            0.750000             -1.975398E+04   -2.252379E+02

********************
Start debug output from TQLR:
  1:T=600, 2:P=100000, 3:N=1, 4:X(CR)=0.25
 Degrees of freedom are   0
T=    600.00 K (   326.85 C), P=  1.0000E+05 Pa, V=  7.2044E-06 m3
N=   1.0000E+00 moles, B=   5.4884E+01 g, RT=   4.9887E+03 J/mol
G= -1.9112E+04 J, G/N= -1.9112E+04 J/mol, H=  9.3417E+03 J, S=  4.7423E+01 J/K
Component name    Moles      Mole-fr  Chem.pot/RT  Activities  Ref.state
CR                2.5000E-01  0.25000 -2.7348E-02  9.7302E-01  BCC_A2
FE                7.5000E-01  0.75000 -4.5150E-02  9.5585E-01  BCC_A2

Name                Status Moles      Volume    Form.Units Cmp/FU dGm/RT  Comp:
BCC_A2.................. E  2.157E-01  1.57E-06  2.16E-01    1.00  0.00E+00  X:
 CR     9.70535E-01  FE     2.94648E-02

BCC_A2_AUTO#2........... E  7.843E-01  5.63E-06  7.84E-01    1.00  0.00E+00  X:
 FE     9.48133E-01  CR     5.18667E-02

End debug output from TQLR
********************


Any more calculations? /N/:

 Auf wiedersehen

C:\Users\...\TQ4lib\F90\crfe>
\end{verbatim}
}

\end{document}

{\small
\begin{verbatim}

\end{verbatim}
}

\end{verbatim}
}

{\small
\begin{verbatim}

